package controller.user.user;

import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import model.entity.User;
import service.Impl.UserServiceImpl;
import util.GetJsonUtil;
import util.ResultUtil;

import java.io.IOException;

@WebServlet("/user/user/register")
public class UserRegisterController extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        User u= (User) GetJsonUtil.get(req,new User());
        UserServiceImpl us=new UserServiceImpl();
        String json;
        if(us.find(u.getUsername())==0){
            us.register(u);
            json= ResultUtil.getJSON(null,"注册成功");
        }
        else json= ResultUtil.getJSON(null,"重复账号");
        resp.getWriter().println(json);
    }
}
